<template>
  <div style="position: relative">
    <el-dialog center :visible.sync="deflag" title="确认删除" width="30%">
      <div slot="footer" class="dialog-footer" style="width: 100%;display: flex;justify-content: space-between">
        <el-button @click="deflag = false">取 消</el-button>
        <el-button type="primary" @click="DelThis">确 定</el-button>
      </div>
    </el-dialog>
    <el-table width="100%" height="70vh" :data="List">
      <el-table-column label="序号"  align="center">
        <template slot-scope="scope">
          {{(currentPage-1)*pageSize+scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column label="题目" align="center">
        <template slot-scope="scope">
          {{TopicList[scope.$index].title}}
        </template>
      </el-table-column>
      <el-table-column label="评分人" align="center">
        <template slot-scope="scope">
          {{UserList[scope.$index].name}}
        </template>
      </el-table-column>
      <el-table-column label="角色" align="center">
        <template slot-scope="scope">
          {{UserRateList[scope.$index].type}}
        </template>
      </el-table-column>
      <el-table-column label="占比" align="center">
        <template slot-scope="scope">
          {{UserRateList[scope.$index].percent}}
        </template>
      </el-table-column>
      <el-table-column label="评分" align="center" prop="num"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="mini" v-if="judge" @click="ShowDel(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <center>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </center>
  </div>
</template>

<script>
import { GetRateList } from '@/api/opus'
import { Remove } from '@/api/rate'

export default {
  name: 'Topic',
  data() {
    return {
      dialogVisible: false,
      dialogTitle: '',
      List: [],
      total: 0,
      currentPage: 1,
      UserList:[],
      TopicList:[],
      UserRateList:[],
      pageSize: 10,
      formData: {
        id: null,
        title: "",
        overview: "",
        isselect: 0
      },
      id: "",
      deflag: false
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    DelThis() {
      let that = this
      Remove(this.id).then(() => {
        that.currentPage = 1
        that.getList()
        that.deflag = false
        this.$message.success("删除成功")
      })
    },
    ShowDel(id) {
      this.id = id
      this.deflag = true
    },
    judge() {
      return localStorage.getItem('role') === '管理员';
    },
    getList() {
      const params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize
      };
      GetRateList(params).then(res => {
        console.log(res)
        this.List = res.ratePage.records;
        this.total = res.ratePage.total;
        this.UserList=res.UserList
        this.TopicList=res.TopicList
        this.UserRateList=res.UserRateList
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      this.$message.success("已修改")
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
  }
}
</script>

<style scoped lang="scss">
.avatar-uploader {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 150px;
  height: 150px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  overflow: hidden;
}

.avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
}
</style>
